// modules/conversationMessage/conversationMessage.controller.ts

import { Provide, Inject } from '@midwayjs/core';
import { CoolController, BaseController, BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn, Repository } from 'typeorm';

/**
 * 会话聊天记录表
 */
@Entity('conversation_message')
export class ConversationMessageEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'int', comment: '会话ID' })
  conversationId: number;

  @Column({ type: 'text', comment: '内容' })
  text: string;

  @Column({ type: 'varchar', length: 8, comment: '类型（问/答）' })
  type: string; // "问" 或 "答"

  @Column({ type: 'int', comment: '用户ID' })
  userId: number;

  @Column({ type: 'int', comment: '所属智能体ID' })
  agentId: number;

  @CreateDateColumn({ type: 'timestamp', comment: '创建时间' })
  createTime: Date;

  @Column({ type: 'int', default: 0, comment: '消耗token数' })
  tokenCount: number;

  // 新增字段：所属分站ID
  @Column({ type: 'int', comment: '所属分站ID' })
  siteId: number;  // 分站ID
}

/**
 * 会话消息控制器
 */
@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: ConversationMessageEntity,
})
export class ConversationMessageController extends BaseController {

  // 如果需要“查指定会话所有消息”这样的特殊接口，可以自定义
  // @Get('/byConversation')
  // async byConversation(@Query('conversationId') conversationId: number) {
  //   const data = await this.messageService.findByConversationId(Number(conversationId));
  //   return this.ok(data);
  // }
}
